package test;

import cn.xdd.dao.BookDao;
import cn.xdd.entity.Book;
import org.apache.log4j.Logger;

import javax.servlet.annotation.WebServlet;
import java.io.File;
import java.sql.SQLException;
import java.util.List;
import java.util.UUID;

/**
 * @author user_xdd
 * @Date 2022-04-12 19:38
 * @description 给数据库中的数据设置uuid
 * @return
 */

public class setUUid {
        private static  final Logger LOGGER = Logger.getLogger(setUUid.class);
    public static void main(String[] args) throws SQLException {
//        获取数据库uuid信息，和book列表信息
        BookDao bookDao = new BookDao();
        List<Book> books = bookDao.getallBook();


        String BasePath ="D:\\my_tool\\OneDrive - xdd307\\弘成\\6.javaWeb\\xdd\\项目设计\\bookManager2.1\\src\\main\\webapp\\data\\book";
        File file = new File(BasePath);
        File[] files = file.listFiles();
        String[] filenames = file.list();
/*        for(String fname:filenames){
             LOGGER.debug("    fname:"+fname);
        }*/

         for(Book book:books){

             String name=book.getBook_address();
//              LOGGER.debug("    name:"+name);
             if(name.equals("0")){
                 String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
                 String   path=BasePath+File.separator+uuid;
                 file=new File(path);
                 int i1 = bookDao.insertUUid(uuid, book.getBook_id());
                 file.mkdirs();
                  LOGGER.debug("    uuid:"+uuid+"书名为"+book.getBook_id());
                 //                file.mkdirs()
//                  LOGGER.debug("    path:"+path);
             }


         }

//        没有相应的文件就生成
           }
}
